<?php
require_once 'Login.php';
require_once 'Kanedo/Controller/Abstract.php';
class loginController extends Kanedo_Controller_Abstract
{
	public function init()
	{
		
	}
	public function indexAction()
	{
		$login = new Login(Kanedo_Registry::getInstance()->db);
		if ($login->isLoggedIn())
		{

			header("Location:".$this->_request->getBaseUrl()."admin/");
		}
	}
	public function doAction()
	{
		$name = $this->_request->getPostParam("name");
		$pw = $this->_request->getPostParam("password");
		$cookie = (bool)$this->_request->getPostParam('cookie');
		if ($name and $pw || $cookie)
		{
			$login = new Login(Kanedo_Registry::getInstance()->db);
			try {
				$login->login($name, $pw, $cookie);
			}catch(Kanedo_Db_Exception $e){
				$this->_view->error = $e->getMessage();
				return;
			}catch (Kanedo_Acl_Exception $e) {
				$this->_view->error = $e->getMessage();
				return;
			}
			
		}else {
			header("Location:".$this->_request->getBaseUrl()."admin/login/");
		}
		
		header("Location:".$this->_request->getBaseUrl()."admin/");
	}
	
	public function logoutAction()
	{
		$login = new Login(Kanedo_Registry::getInstance()->db);
		$login->logout();
		header("Location:".$this->_request->getBaseUrl());
	}
}
?>